/**
 * 判断用户是否同意授权
 * @param agreeType 同意字段
 * @param title 授权弹窗标题
 * @param tips 授权提示词
 * @param success 成功回调
 * @param fail 失败回调
 * @return {boolean} 返回值(Boolean)
 */
export function localAgree(agreeType, title, tips, success, fail) {
  const agree = uni.getStorageSync(`${agreeType}`)
  if (agree) {
    uni.setStorageSync(`${agreeType}`, true)
    return true
  } else {
    uni.showModal({
      title: title || '提示',
      content: `${tips}`,
      success: function(res) {
        if (res.confirm) {
          uni.setStorageSync(`${agreeType}`, true)
          if (success) {
            success()
          }
          return true
        } else if (res.cancel) {
          uni.setStorageSync(`${agreeType}`, false)
          if (fail) {
            fail()
          }
          return false
        }
      }
    })
  }
}
